#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <openssl/blowfish.h>
#include <openssl/md5.h>

int encrypt(char *data, unsigned long size)
{
	BF_KEY key;
	unsigned long i;
	unsigned char *k_data = data+size;
	unsigned char *hash;

	srand(time(NULL));

	for(i = 0; i < 16; i++){
		k_data[i] = rand()%256;
	}

	BF_set_key(&key, 16, k_data);

	for(i = 0; i < size; i += 8){
		BF_ecb_encrypt(data+i, data+i, &key, BF_ENCRYPT);
	}

	hash = MD5(data, (size_t)size, NULL);

	for(i = 0; i < 16; i++){
		k_data[i] = (hash[i] ^ k_data[i]);
	}
	
	return 0;
}
